package com.ice.cloud.payManagement.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.ice.cloud.comm.resp.R;
import com.ice.cloud.comm.resp.ReturnCodeEnum;
import com.ice.cloud.payManagement.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.persistence.criteria.CriteriaBuilder;

@RestController
@RequestMapping("/paySentinel")
public class PaySentinelController {

    @Autowired
    AccountService accountService;

    @GetMapping(value = "feeDeductionSentinel")
    @SentinelResource(value = "feeDeductionSentinel",blockHandler = "handlerBlockHandler")
    public R<String> feeDeductionSentinel(@RequestParam("id") Integer id,@RequestParam("money") Double money){
        R<String> r = accountService.feeDeduction(id,money);
        return r;
    }
    public R handlerBlockHandler(@RequestParam("id") Integer id,@RequestParam("money") Double money, BlockException exception){
        System.out.println(id+"------" +money);
        return R.error(ReturnCodeEnum.RC500.getCode(), "feeDeductionSentinel不可用");

    }
}
